using System;
using UnityEngine;

public class AndroidNativeAudio
{
	private static bool DEBUG;

	private const int LOAD_PRIORITY = 1;

	private const int SOURCE_QUALITY = 0;

	/* private static AndroidJavaObject assetFileDescriptor;

	private static AndroidJavaObject assets;

	private static AndroidJavaObject soundPool; */

	private static bool hasOBB;

	private static int streamMusic;

	static AndroidNativeAudio()
	{
		/* DEBUG = false;
		soundPool = null;
		streamMusic = new AndroidJavaClass("android.media.AudioManager").GetStatic<int>("STREAM_MUSIC");
		AndroidJavaObject @static = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
		if (Application.streamingAssetsPath.Substring(Application.streamingAssetsPath.Length - 12) == ".obb!/assets")
		{
			hasOBB = true;
			int num = @static.Call<AndroidJavaObject>("getPackageManager", new object[0]).Call<AndroidJavaObject>("getPackageInfo", new object[2]
			{
				@static.Call<string>("getPackageName", new object[0]),
				0
			}).Get<int>("versionCode");
			try
			{
				assets = new AndroidJavaClass("com.android.vending.expansion.zipfile.APKExpansionSupport").CallStatic<AndroidJavaObject>("getAPKExpansionZipFile", new object[3]
				{
					@static,
					num,
					0
				});
			}
			catch (Exception ex)
			{
				UnityEngine.Debug.Log(ex.ToString());
			}
		}
		else
		{
			hasOBB = false;
			assets = @static.Call<AndroidJavaObject>("getAssets", new object[0]);
		} */
	}

	public static int load(string audioFile, bool usePersistentDataPath = false)
	{
		/* audioFile = audioFile.Replace("\\", "/");
		if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: load(\"" + audioFile + "\", " + usePersistentDataPath + ")");
		}
		if (soundPool == null)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: Use makePool() before load()!");
			return -1;
		}
		try
		{
			if (usePersistentDataPath)
			{
				return soundPool.Call<int>("load", new object[2]
				{
					Application.persistentDataPath + "/" + audioFile,
					1
				});
			}
			if (hasOBB)
			{
				assetFileDescriptor = assets.Call<AndroidJavaObject>("getAssetFileDescriptor", new object[1]
				{
					"assets/" + audioFile
				});
			}
			else
			{
				assetFileDescriptor = assets.Call<AndroidJavaObject>("openFd", new object[1]
				{
					audioFile
				});
			}
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
			return -1;
		}
		try
		{
			return soundPool.Call<int>("load", new object[2]
			{
				assetFileDescriptor,
				1
			});
		}
		catch (Exception ex2)
		{
			UnityEngine.Debug.Log(ex2.ToString());
			return -1;
		} */
		return -1;
	}

	public static void makePool(int maxStreams)
	{
		/* if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: makePool(" + maxStreams.ToString() + ")");
		}
		if (soundPool != null)
		{
			soundPool.Call("release");
		} */
		//soundPool = new AndroidJavaObject("android.media.SoundPool", maxStreams, streamMusic, 0);
	}

	public static void pause(int streamID)
	{
		/* if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: pause(" + streamID.ToString() + ")");
		}
		try
		{
			soundPool.Call("pause", streamID);
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
		} */
	}

	public static void pauseAll()
	{
		/* if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: pauseAll()");
		}
		try
		{
			soundPool.Call("autoPause");
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
		} */
	}

	public static int play(int soundID, float leftVolume = 1f, float rightVolume = -1f, int priority = 1, int loop = 0, float rate = 1f)
	{
		if (rightVolume == -1f)
		{
			rightVolume = leftVolume;
		}
		/* if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: play(" + soundID.ToString() + ", " + leftVolume.ToString() + ", " + rightVolume.ToString() + ", " + priority.ToString() + ", " + loop.ToString() + ", " + rate.ToString() + ")");
		}
		try
		{
			return soundPool.Call<int>("play", new object[6]
			{
				soundID,
				leftVolume,
				rightVolume,
				priority,
				loop,
				rate
			});
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
			return -1;
		} */
		return -1;
	}

	public static void releasePool()
	{
		if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: releasePool()");
		}
		/* try
		{
			soundPool.Call("release");
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
			return;
		}
		soundPool = null; */
	}

	public static void resume(int streamID)
	{
		if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: resume(" + streamID.ToString() + ")");
		}
		/* try
		{
			soundPool.Call("resume", streamID);
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
		} */
	}

	public static void resumeAll()
	{
		if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: resumeAll()");
		}
		/* try
		{
			soundPool.Call("autoResume");
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
		} */
	}

	public static void setLoop(int streamID, int loop)
	{
		if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: setLoop(" + streamID.ToString() + ", " + loop.ToString() + ")");
		}
		/* try
		{
			soundPool.Call("setLoop", streamID, loop);
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
		} */
	}

	public static void setPriority(int streamID, int priority)
	{
		if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: setPriority(" + streamID.ToString() + ", " + priority.ToString() + ")");
		}
		/* try
		{
			soundPool.Call("setPriority", streamID, priority);
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
		} */
	}

	public static void setRate(int streamID, float rate)
	{
		if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: setRate(" + streamID.ToString() + ", " + rate.ToString() + ")");
		}
		/* try
		{
			soundPool.Call("setRate", streamID, rate);
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
		} */
	}

	public static void setVolume(int streamID, float leftVolume, float rightVolume = -1f)
	{
		if (rightVolume == -1f)
		{
			rightVolume = leftVolume;
		}
		if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: setVolume(" + streamID.ToString() + ", " + leftVolume.ToString() + ", " + rightVolume.ToString() + ")");
		}
		/* try
		{
			soundPool.Call("setVolume", streamID, leftVolume, rightVolume);
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
		} */
	}

	public static void stop(int streamID)
	{
		if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: stop(" + streamID.ToString() + ")");
		}
		/* try
		{
			soundPool.Call("stop", streamID);
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
		} */
	}

	public static bool unload(int soundID)
	{
		if (DEBUG)
		{
			UnityEngine.Debug.Log("AndroidNativeAudio: unload(" + soundID.ToString() + ")");
		}
		/* try
		{
			return soundPool.Call<bool>("unload", new object[1]
			{
				soundID
			});
		}
		catch (Exception ex)
		{
			UnityEngine.Debug.Log(ex.ToString());
			return false;
		} */
		return false;
	}
}
